$(() => {
    $('#resetPasswordForm').on('submit', function () {
        const formData = $(this).serializeArray()
        const formDataObj = {}
        formData.forEach((v) => {
            formDataObj[v.name] = v.value
        })
        console.log(formDataObj);
        if (formDataObj.userPass === '') {
            alert('请输入旧密码')
            return false
        }
        if (formDataObj.newPass === '') {
            alert('请输入新密码')
            return false
        }
        if (formDataObj.confirmPass === '') {
            alert('请确认新密码')
            return false
        }
        $.ajax({
            type: 'put',
            url: '/users/password',
            data: formDataObj,
            success(res) {
                $.ajax({
                    type: 'post',
                    url: '/logout',
                    success(res) {
                        location.href = '/admin/login.html'
                    },
                    error() {
                        alert('退出失败!')
                    }
                })
            },
            error(res) {
                alert(JSON.parse(res.responseText).message)
            }
        })

        return false
    })
})